﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DavidDB.ADO;
namespace TimeAxis
{
    public partial class Map : System.Web.UI.Page
    {
        public List<Models.Category> categorys = new List<Models.Category>();
        public List<Models.Doc> docs = new List<Models.Doc>();
        protected void Page_Load(object sender, EventArgs e)
        {
            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            categorys = Impls.ImplCategory.GetInstance(db).GetList();
            if (!string.IsNullOrEmpty(Request.QueryString["cid"]))
            {
                string sql = "select a.* from Doc a,DocCategory b,Category c where a.Id=b.DocId and c.Id=b.CategoryId and c.Id=" + Request.QueryString["cid"] + " order by a.GoodCount desc";
                System.Data.OleDb.OleDbDataReader sdr = db.ExecuteReader(sql);
                while (sdr.Read())
                {
                    Models.Doc td = new Models.Doc();
                    td.Id = Convert.ToInt32(sdr["Id"]);
                    td.Content = sdr["Content"].ToString();
                    td.Pdate = Convert.ToDateTime(sdr["Pdate"]);
                    td.GoodCount = Convert.ToInt32(sdr["GoodCount"]);
                    td.Title = sdr["Title"].ToString();
                    td.UsersId = Convert.ToInt32(sdr["UsersId"]);
                    docs.Add(td);
                }
                foreach (Models.Doc doc in docs)
                {
                    doc.Include("Users", db);
                }
                sdr.Close();
            }
            else
            {
                docs = Impls.ImplDoc.GetInstance(db).GetList().OrderBy(a => a.GoodCount).ToList();
                foreach (Models.Doc doc in docs)
                {
                    doc.Include("Users", db);
                }
            }

            db.Commit();
            db.Dispose();
        }
    }
}